home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Examples / DemoDialogs / UDemoDialogs.cp < prev    next >
Encoding:
Text File  |  1996-04-03  |  45.8 KB  |  1,523 lines  |  [TEXT/MPS ]

  1. //----------------------------------------------------------------------------------------
  2. // UDemoDialogs.cp 
  3. // Copyright © 1988-96 by Apple Computer, Inc. All rights reserved.
  4. //----------------------------------------------------------------------------------------
  5.  
  6. #ifndef __UDEMODIALOGS__
  7. #include "UDemoDialogs.h"
  8. #endif
  9.  
  10. // DemoDialogs
  11.  
  12. #ifndef __USTRUCTUREINSPECTORS__
  13. #include "UStructureInspectors.h"
  14. #endif
  15.  
  16. // MacApp
  17.  
  18. #ifndef __UCONTROL__
  19. #include "UControl.h"
  20. #endif
  21.  
  22. #ifndef __UDRAWINGENVIRONMENT__
  23. #include "UDrawingEnvironment.h"
  24. #endif
  25.  
  26. #ifndef __UFAILURE__
  27. #include "UFailure.h"
  28. #endif
  29.  
  30. #ifndef __UGEOMETRY__
  31. #include "UGeometry.h"
  32. #endif
  33.  
  34. #ifndef __UKEYSELECTIONBEHAVIOR__
  35. #include "UKeySelectionBehavior.h"
  36. #endif
  37.  
  38. #ifndef __UMACAPPUTILITIES__
  39. #include "UMacAppUtilities.h"
  40. #endif
  41.  
  42. #ifndef __UMEMORY__
  43. #include "UMemory.h"
  44. #endif
  45.  
  46. #ifndef __UMENUMGR__
  47. #include "UMenuMgr.h"
  48. #endif
  49.  
  50. #ifndef __UPOPUP__
  51. #include "UPopup.h"
  52. #endif
  53.  
  54. #ifndef __UPRINTING__
  55. #include "UPrinting.h"
  56. #endif
  57.  
  58. #ifndef __USCROLLER__
  59. #include "UScroller.h"
  60. #endif
  61.  
  62. #ifndef __USUBSTITUTION__
  63. #include "USubstitution.h"
  64. #endif
  65.  
  66. #ifndef __UTABBEHAVIORS__
  67. #include "UTabBehaviors.h"
  68. #endif
  69.  
  70. #ifndef __UTEVIEW__
  71. #include "UTEView.h"
  72. #endif
  73.  
  74. #ifndef __UVIEWSERVER__
  75. #include "UViewServer.h"
  76. #endif
  77.  
  78. #ifndef __UWINDOW__
  79. #include "UWindow.h"
  80. #endif
  81.  
  82. // Toolbox
  83.  
  84. #ifndef __FONTS__
  85. #include <Fonts.h>
  86. #endif
  87.  
  88. #ifndef __FP__
  89. #include <fp.h>
  90. #endif
  91.  
  92. #ifndef __MENUS__
  93. #include <Menus.h>
  94. #endif
  95.  
  96. #ifndef __OSUTILS__
  97. #include <OSUtils.h>
  98. #endif
  99.  
  100. #ifndef __PACKAGES__
  101. #include <Packages.h>
  102. #endif
  103.  
  104. #ifndef __RESOURCES__
  105. #include <Resources.h>
  106. #endif
  107.  
  108. #ifndef __RESOURCES__
  109. #include <Resources.h>
  110. #endif
  111.  
  112. #ifndef __TOOLUTILS__
  113. #include <ToolUtils.h>
  114. #endif
  115.  
  116. // ANSI
  117.  
  118. #ifndef __LIMITS__
  119. #include <limits.h>
  120. #endif
  121.  
  122. #ifndef __STDIO__
  123. #include <stdio.h>
  124. #endif
  125.  
  126. #ifndef __STDLIB__
  127. #include <stdlib.h>
  128. #endif
  129.  
  130. //----------------------------------------------------------------------------------------
  131. // Constants
  132. const short kDynamicPopup = 300;
  133.  
  134. const short kNoOfLines = 10000;
  135. const short kMaxScrollBar = 1000;
  136. const short kTestIcon = 1000;
  137. const short kTestAlert = 1000;
  138. const short kTestPopup = 235;
  139. const short kBaudPopup = 236;
  140. const short kParityPopup = 237;
  141. const short kPopup = 238;
  142.  
  143. const short kTextStylePopup = 239;
  144. const short kFontHier = 230;
  145. const short kStyleHier = 231;
  146. const short kSizeHier = 232;
  147.  
  148. const short kTestPicture = 1000;
  149. const short kTestStatic = 1200;
  150.  
  151. // Constants for Command Items
  152. const short cFirstItem = 1001;
  153. const short cProcedureViews = 1001;
  154. const short cTemplateViews = 1002;
  155. const short cMonthlyDialog = 1003;
  156. const short cSaveDialog = 1004;
  157. const short cModalBeepDialog = 1005;
  158. const short cPageSetupDialog = 1006;
  159. const short cHomeBrewControls = 1007;
  160. const short cTabbingTest = 1008;
  161. const short cCalculator = 1009;
  162. const short cScrollingTest = 1011;
  163. const short cFormatDialog = 1012;
  164. const short cModelessBeepDialog = 1013;
  165. const short cMessageWindoid = 1014;
  166. const short cBalloons = 1015;
  167. const short cAdornment = 1016;
  168. const short cViewInspector = 1017;
  169. const short cTargetInspector = 1018;
  170. const short cLastItem = 1018;
  171. const short cPopupExample = 1100;
  172. const short cTextStyleChanged = 1102;
  173. const short cResetTextStyle = 1103;
  174.  
  175. //----------------------------------------------------------------------------------------
  176.  
  177. struct FondRecord
  178. {
  179.     FamRec familyStuff;
  180.     short noOfFonts;
  181.     struct
  182.     {
  183.         short size;
  184.         short style;
  185.         short resID;
  186.     } fontStuff[1001];
  187. };
  188.  
  189.  
  190. typedef FondRecord* FondPointer, ** FondHandle;
  191.  
  192. long gMonthlyValues[13];
  193. IDType gMonthIDs[13];
  194.  
  195.  
  196. //========================================================================================
  197. // Global Functions
  198. //========================================================================================
  199. static Boolean GetFontNumber( CStr255& fontName, short& fontNumber );
  200.  
  201. //========================================================================================
  202. // CLASS TTestApplication
  203. //========================================================================================
  204. #undef Inherited
  205. #define Inherited TApplication
  206.  
  207. #pragma segment AInit
  208. MA_DEFINE_CLASS_M1(TTestApplication, Inherited);
  209.  
  210. //----------------------------------------------------------------------------------------
  211. // TTestApplication destructor
  212. //----------------------------------------------------------------------------------------
  213. #pragma segment MADestructorRes
  214.  
  215. TTestApplication::~TTestApplication()
  216. {
  217. }
  218.  
  219. //----------------------------------------------------------------------------------------
  220. // TTestApplication::ITestApplication: 
  221. //----------------------------------------------------------------------------------------
  222. #pragma segment AInit
  223.  
  224. void TTestApplication::ITestApplication()
  225.  
  226. {
  227.     const char* monthIDs = "jan feb mar apr may jun jul aug sep oct nov dec ";
  228.  
  229.  
  230.     IApplication(kFileType, kSignature);
  231.  
  232.     fLaunchWithNewDocument = FALSE;        // Suppress the creation of a new document at launch
  233.  
  234.     for (short i = 0; i < 12; i++)
  235.     {
  236.         gMonthlyValues[i] = (i + 1) * 100;
  237.     }
  238.  
  239.     MABlockMove(monthIDs, (Ptr)gMonthIDs, sizeof(gMonthIDs));
  240.  
  241.     // Suppress dead-stripping of the following classes 
  242.     MA_REGISTER_CLASS(TDrawingEnvironment);
  243.     MA_REGISTER_CLASS(TMonthlyDialog);
  244.     MA_REGISTER_CLASS(TArrowsControl);
  245.     MA_REGISTER_CLASS(TTemperatureCluster);
  246.     MA_REGISTER_CLASS(TTemperatureConversionCluster);
  247.     MA_REGISTER_CLASS(TSlider);
  248.     MA_REGISTER_CLASS(TFontListView);
  249.     MA_REGISTER_CLASS(TSizeListView);
  250.     MA_REGISTER_CLASS(TRadioIcon);
  251.     MA_REGISTER_CLASS(TPageSetupDialog);
  252.     MA_REGISTER_CLASS(TSumStaticText);
  253.     MA_REGISTER_CLASS(TCalcDialog);
  254.     MA_REGISTER_CLASS(TNumbersView);
  255.     MA_REGISTER_CLASS(TNumberListView);
  256.     MA_REGISTER_CLASS(TViewHierarchyView);
  257.     MA_REGISTER_CLASS(TTargetChainView);
  258.     MA_REGISTER_CLASS(TModelessBeepDialog);
  259.     MA_REGISTER_CLASS(TScrollBar);
  260.  
  261.     MA_REGISTER_CLASS(TAdornmentDemo);
  262.     MA_REGISTER_CLASS(TEmbossedFrame);
  263.     MA_REGISTER_CLASS(TGrayFill);
  264.     MA_REGISTER_CLASS(TEtchedFrame);
  265.     MA_REGISTER_CLASS(TSlowScroller);
  266.  
  267.  
  268.     MA_REGISTER_SIGNATURE(TEmbossedFrame, 'embo');
  269.     MA_REGISTER_SIGNATURE(TGrayFill, 'gray');
  270.     MA_REGISTER_SIGNATURE(TEtchedFrame, 'etch');
  271.     MA_REGISTER_SIGNATURE(TRoundView, 'rndV');
  272.  
  273.     // to demonstrate support of dynamic menus with TPopup 
  274.     CStr255 menuName = "Fonts:";
  275.     fMenuRef = NewMenu(kDynamicPopup, menuName);
  276.     FailNIL(fMenuRef);
  277.     AppendResMenu(fMenuRef, 'FONT');
  278.     MAInsertInMenuTable(fMenuRef, kDynamicPopup);
  279.     
  280. /*    TSwallowBehavior* aSwallowBehavior = new TSwallowBehavior;*/
  281. /*    aSwallowBehavior->IBehavior(kNoIdentifier);*/
  282. /*    this->AddBehavior(aSwallowBehavior);*/
  283. } // TTestApplication::ITestApplication 
  284.  
  285. //----------------------------------------------------------------------------------------
  286. // TTestApplication::DoMakeDocument: 
  287. //----------------------------------------------------------------------------------------
  288. #pragma segment AOpen
  289.  
  290. TDocument* TTestApplication::DoMakeDocument(CommandNumber    /*itsCommandNumber*/,
  291.                                                    TFile*           /*itsFile*/ )// override 
  292.  
  293. {
  294.     return NULL;
  295. } // TTestApplication::DoMakeDocument 
  296.  
  297. //----------------------------------------------------------------------------------------
  298. // TTestApplication::MakeProcedureViews: 
  299. //----------------------------------------------------------------------------------------
  300. #pragma segment ASelCommand
  301.  
  302. void TTestApplication::MakeProcedureViews(CommandNumber aCommandNumber)
  303.  
  304. {
  305.     TextStyle        aTextStyle;
  306.     short             i;
  307.     CRGBColor         aColor;
  308.     VPoint             itsLocation;
  309.     VPoint             itsSize;
  310.     TextStyle         ts;
  311.     TWindow *         aWindow;
  312.     TView *         aTestView;
  313.     TCluster *         aCluster;
  314.     TRadio *         aRadio[8];
  315.     TButton *         aButton;
  316.     TIcon *         anIcon;
  317.     TCheckBox *     aCheckBox;
  318.     TPopup *         aPopup;
  319.     TPicture *         aPicture;
  320.     TStaticText *    aStaticText;
  321.     TEditText *        anEditText;
  322.     VRect            itsInset;
  323.     VPoint            itsInsetDelta;
  324.     CPoint            aPoint;
  325.     const CStr255    StyleName[8] = {"Plain",    "Bold",        "Italic",    "Underline", 
  326.                                     "Outline",    "Shadow",    "Condense",    "Extend"};
  327.     const CStr255    ParamSubs0 = "^0";
  328.     const CStr255     ParamSubs1 = "^1";
  329.     const CStr255    ExpansionSubs0 = "PARAM0";
  330.     const CStr255    ExpansionSubs1 = "PARAM1";
  331.  
  332.     aTestView = new TView;
  333.     itsSize = VPoint(480, 1200);
  334.     aTestView->IView(NULL, NULL, gZeroVPt, itsSize, sizeFixed, sizeFixed);
  335.     MAParamText(ParamSubs0, ExpansionSubs0);
  336.     MAParamText(ParamSubs1, ExpansionSubs1);
  337.  
  338.     FailNIL(aWindow = gViewServer->NewSimpleWindow((short)aCommandNumber, TRUE, TRUE, NULL, aTestView));
  339.     aWindow->fFreeOnClosing = TRUE;
  340.  
  341.     aStaticText = new TStaticText;
  342.     itsLocation = VPoint(50, 100);
  343.     itsSize = VPoint(300, 150);
  344.     aStaticText->IStaticText(aTestView, itsLocation, itsSize, sizeVariable, sizeVariable, kTestStatic, 1);
  345.     SetRGBColor(aColor, 0, 0, 0xFFFF);
  346.     SetTextStyle(ts, applFont, italic, 12, aColor);
  347.     aStaticText->InstallTextStyle(ts, kDontRedraw);
  348.     aStaticText->SetJustification(teCenter, kRedraw);
  349.     
  350.     aCluster = new TCluster;
  351.     itsLocation = VPoint(100, 340);
  352.     itsSize = VPoint(150, 190);
  353.     aCluster->ICluster(aTestView, itsLocation, itsSize, sizeVariable, sizeVariable, kNoResource, 0);
  354.     aCluster->SetLabel("A Cluster!", kRedraw);
  355.  
  356.     itsSize = VPoint(130, 20);
  357.     for (i = 0; i < 8; i++)
  358.     {
  359.         aRadio[i] = new TRadio;
  360.         itsLocation = VPoint(10, (i + 1) * 20);
  361.         aRadio[i]->IRadio(aCluster, itsLocation, itsSize, sizeVariable, sizeVariable, gEmptyString, i == 2);
  362.         SetTextStyle(ts, systemFont, Style((1 << i) / 2), 12, gRGBBlack);
  363.         aRadio[i]->InstallTextStyle(ts, kDontRedraw);
  364.         aRadio[i]->SetText(StyleName[i], kRedraw);
  365.     }
  366.  
  367.     aCheckBox = new TCheckBox;
  368.     itsLocation = VPoint(100, 540);
  369.     itsSize = VPoint(100, 20);
  370.     aCheckBox->ICheckBox(aTestView, itsLocation, itsSize, sizeVariable, sizeVariable, "Check Box", FALSE);
  371.     SetTextStyle(ts, applFont, 0, 12, gRGBBlack);
  372.     aCheckBox->InstallTextStyle(ts, kRedraw);
  373.  
  374.     aButton = new TButton;
  375.     itsLocation = VPoint(270, 540);
  376.     itsSize = VPoint(100, 28);
  377.     aButton->IButton(aTestView, itsLocation, itsSize, sizeVariable, sizeVariable, "Push Button");
  378.     SetTextStyle(ts, applFont, NULL, 10, gRGBBlack);
  379.     aButton->InstallTextStyle(ts, kDontRedraw);
  380.     aButton->SetPenSize(CPoint(3, 3));
  381.     aButton->SetAdornment(adnRRect, kDontRedraw);
  382.     itsInsetDelta = VPoint(4, 4);
  383.     aButton->Inset(itsInsetDelta, kRedraw);
  384.  
  385.     anIcon = new TIcon;
  386.     itsLocation = VPoint(130, 570);
  387.     itsSize = VPoint(35, 35);
  388.     anIcon->IIcon(aTestView, itsLocation, itsSize, sizeFixed, sizeFixed, kTestIcon, kPreferColor);
  389.     anIcon->SetAdornment(kFrame | adnShadow, kDontRedraw);
  390.  
  391.     anIcon->ViewEnable(TRUE, kDontRedraw);
  392.     itsInset = VRect(1, 1, 1, 1);
  393.     anIcon->SetInset(itsInset, kDontRedraw);
  394.  
  395.     aPopup = new TPopup;                        // test popup 
  396.     itsLocation = VPoint(290, 589);
  397.     itsSize = VPoint(120, 22);
  398.     aPopup->IPopup(aTestView, itsLocation, itsSize, sizeVariable, sizeVariable, kTestPopup, 2, 50, cPopupExample, 1, NULL, teJustLeft, kDontUseAddResMenu, kNoIdentifier);
  399.  
  400.     aPopup = new TPopup;                        // baud popup
  401.     itsLocation = VPoint(290, 624);
  402.     itsSize = VPoint(120, 22);
  403.     aPopup->IPopup(aTestView, itsLocation, itsSize, sizeVariable, sizeVariable, kBaudPopup, 1, 50, cPopupExample, 2, NULL, teJustLeft, kDontUseAddResMenu, kNoIdentifier);
  404.  
  405.     aPopup = new TPopup;                        // parity popup 
  406.     itsLocation = VPoint(290, 659);
  407.     itsSize = VPoint(120, 22);
  408.     aPopup->IPopup(aTestView, itsLocation, itsSize, sizeVariable, sizeVariable, kParityPopup, 1, 50, cPopupExample, 3, 0, teJustLeft, kDontUseAddResMenu, kNoIdentifier);
  409.     SetTextStyle(aTextStyle, applFont, NULL, 9, gRGBBlack);
  410.     aPopup->fTextStyle = aTextStyle;
  411.  
  412.     aPicture = new TPicture;
  413.     itsLocation = VPoint(100, 660);
  414.     itsSize = VPoint(0x18C - 0xF0 + 16, 0x12C - 0x8F + 16);
  415.     aPicture->IPicture(aTestView, itsLocation, itsSize, sizeVariable, sizeVariable, kTestPicture);
  416.         //    aPicture->fPenSize = CPoint(0x00020002);
  417.     aPicture->SetAdornment(adnRRect | adnShadow, kDontRedraw);
  418.     aPicture->ViewEnable(TRUE, kDontRedraw);
  419.     itsInsetDelta = VPoint(8, 8);
  420.     aPicture->Inset(itsInsetDelta, kDontRedraw);
  421.     aPicture->SetLocalOrigin(VPoint(50, 50), kDontRedraw);
  422.     aPicture->UpdateCoordinates();
  423.  
  424.  
  425.     anEditText = new TEditText;
  426.     itsLocation = VPoint(140, 620);
  427.     itsSize = VPoint(100, 22);
  428.     anEditText->IEditText(aTestView, itsLocation, itsSize, 255);
  429.     SetTextStyle(ts, applFont, 0, 12, gRGBBlack);
  430.     anEditText->InstallTextStyle(ts, kDontRedraw);
  431.     anEditText->SetJustification(teFlushRight, kDontRedraw);
  432.     anEditText->SetText("EditText", kDontRedraw);
  433.  
  434.     aWindow->Open();
  435. } // TTestApplication::MakeProcedureViews 
  436.  
  437. //----------------------------------------------------------------------------------------
  438. // TTestApplication::DoMenuCommand: 
  439. //----------------------------------------------------------------------------------------
  440. #pragma segment ASelCommand
  441.  
  442. void TTestApplication::DoMenuCommand(CommandNumber aCommandNumber)// override 
  443.  
  444.  
  445. {
  446.     switch (aCommandNumber)
  447.     {
  448.         case cProcedureViews:
  449.             MakeProcedureViews(aCommandNumber);
  450.             break;
  451.         case cTemplateViews:
  452.             MakeTemplateViews(aCommandNumber);
  453.             break;
  454.         case cScrollingTest:
  455.             MakeScrollingTest(aCommandNumber);
  456.             break;
  457.         case cMonthlyDialog:
  458.             MakeMonthlyDialog(aCommandNumber);
  459.             break;
  460.         case cSaveDialog:
  461.             MakeSaveDialog(aCommandNumber);
  462.             break;
  463.         case cModalBeepDialog:
  464.             MakeModalBeepDialog(aCommandNumber);
  465.             break;
  466.         case cModelessBeepDialog:
  467.             MakeDialog(aCommandNumber);
  468.             break;
  469.         case cMessageWindoid:
  470.             MakeDialog(aCommandNumber);
  471.             break;
  472.         case cViewInspector:
  473.         case cTargetInspector:
  474.             {
  475.                 TWindow *    aWindow;
  476.             
  477.                 FailNIL(aWindow = gViewServer->NewTemplateWindow((short)aCommandNumber, NULL));
  478.                 aWindow->SetResizeLimits(CPoint(210,180),CPoint(210,1000));
  479.                 aWindow->Open();
  480.             }
  481.             break;
  482.         case cBalloons:
  483.             MakeBalloonWindow(aCommandNumber);
  484.             break;
  485.         case cAdornment:
  486.             MakeDialog(aCommandNumber);
  487.             break;
  488.         case cFormatDialog:
  489.             MakeFormatDialog(aCommandNumber);
  490.             break;
  491.         case cPageSetupDialog:
  492.             MakePageSetupDialog(aCommandNumber);
  493.             break;
  494.         case cHomeBrewControls:
  495.             MakeHomeBrewDialog(aCommandNumber);
  496.             break;
  497.         case cTabbingTest:
  498.             MakeDialog(aCommandNumber);
  499.             break;
  500.         case cCalculator:
  501.             MakeCalculator(aCommandNumber);
  502.             break;
  503.         default:
  504.             Inherited::DoMenuCommand(aCommandNumber);
  505.             break;
  506.     }
  507. } // TTestApplication::DoMenuCommand 
  508.  
  509. //----------------------------------------------------------------------------------------
  510. // TTestApplication::DoSetupMenus: 
  511. //----------------------------------------------------------------------------------------
  512. #pragma segment ARes
  513.  
  514. void TTestApplication::DoSetupMenus()// override 
  515.  
  516. {
  517.     Inherited::DoSetupMenus();
  518.  
  519.     for (short i = cFirstItem; i <= cLastItem; i++)
  520.         Enable(i, TRUE);
  521.  
  522.     Enable(cAdornment, HasColorQD());
  523.  
  524.     // If the Dynamic menu is not in the menubar then insert it 
  525.     if (::GetMenuHandle((*fMenuRef)->menuID) == NULL)
  526.         MAInsertMenu(fMenuRef, (*fMenuRef)->menuID, -1);
  527.  
  528. } // TTestApplication::DoSetupMenus 
  529.  
  530.  
  531. //----------------------------------------------------------------------------------------
  532. // TTestApplication::MakeTemplateViews: 
  533. //----------------------------------------------------------------------------------------
  534. void TTestApplication::MakeTemplateViews(CommandNumber aCommandNumber)
  535.  
  536. {
  537.     TWindow *        aWindow;
  538.     TDialogView *    aDialogView;
  539.     TPopup *        aPopup;
  540.  
  541.  
  542.     FailNIL(aWindow = gViewServer->NewTemplateWindow((short)aCommandNumber, NULL));
  543.     aDialogView = (TDialogView *)(aWindow->FindSubView('DLOG'));
  544.  
  545.  
  546.     TStdPrintHandler* aPrintHandler = new TStdPrintHandler;
  547.     aPrintHandler->IStdPrintHandler(NULL,            // its document 
  548.                                     aDialogView,        // its view 
  549.                                     !kFixedSize,    // horizontal page size is variable 
  550.                                     kFixedSize);    // vertical page size is fixed 
  551.  
  552.  
  553.     FailNIL(aPopup = (TPopup *)(gViewServer->DoCreateViews(NULL, aDialogView, cPopupExample, gZeroVPt)));
  554.     MAParamText("^0", "PARAM0");
  555.     MAParamText("^1", "PARAM1");
  556.     aWindow->Open();
  557. } // TTestApplication::MakeTemplateViews 
  558.  
  559. //----------------------------------------------------------------------------------------
  560. // TTestApplication::MakeScrollingTest: 
  561. //----------------------------------------------------------------------------------------
  562. void TTestApplication::MakeScrollingTest(CommandNumber aCommandNumber)
  563.  
  564. {
  565.     TWindow *    aWindow;
  566.     CPoint        minSize;
  567.  
  568.  
  569.     FailNIL(aWindow = gViewServer->NewTemplateWindow((short)aCommandNumber, NULL));
  570.     SetPt(minSize, 315, 260);
  571.     aWindow->SetResizeLimits(minSize, aWindow->fResizeLimits[botRight]);
  572.     aWindow->Open();
  573. } // TTestApplication::MakeScrollingTest 
  574.  
  575. //----------------------------------------------------------------------------------------
  576. // TTestApplication::MakeMonthlyDialog: 
  577. //----------------------------------------------------------------------------------------
  578. void TTestApplication::MakeMonthlyDialog(CommandNumber aCommandNumber)
  579.  
  580. {
  581.     TWindow *             aWindow;
  582.     TMonthlyDialog *    aMonthlyDialog;
  583.     TViewTabber *        aTabber;
  584.  
  585.  
  586.     FailNIL(aWindow = gViewServer->NewTemplateWindow((short)aCommandNumber, NULL));
  587.     aMonthlyDialog = (TMonthlyDialog *)(aWindow->FindSubView('DLOG'));
  588.     if (aMonthlyDialog != NULL)
  589.         aMonthlyDialog->StuffValues();
  590.  
  591.     // Add a tabbing behavior to the window. This shows how to prevent cross-window
  592.     // tabbing when there are floating windows present
  593.     aTabber = new TViewTabber;
  594.     aTabber->ITabber(TRUE);
  595.     aWindow->AddBehavior(aTabber);
  596.  
  597.     aWindow->Open();
  598. } // TTestApplication::MakeMonthlyDialog 
  599.  
  600. //----------------------------------------------------------------------------------------
  601. // TTestApplication::MakeSaveDialog: 
  602. //----------------------------------------------------------------------------------------
  603. void TTestApplication::MakeSaveDialog(CommandNumber aCommandNumber)
  604.  
  605. {
  606.     TWindow *    aWindow;
  607.     IDType        dismisser;
  608.  
  609.  
  610.     FailNIL(aWindow = gViewServer->NewTemplateWindow((short)aCommandNumber, NULL));
  611.     dismisser = aWindow->PoseModally();
  612.  
  613. #if qDebug
  614.     if (dismisser == 'yes ')
  615.         fprintf(stderr, "The user said yes.\n");
  616.     else if (dismisser == 'no  ')
  617.         fprintf(stderr, "The user said no.\n");
  618.     else if (dismisser == 'cncl')
  619.         fprintf(stderr, "The user cancelled the dialog.\n");
  620.     else
  621.         fprintf(stderr, "I don't know how the user responded\n");
  622. #endif
  623.  
  624.     aWindow->Close();
  625.     aWindow->Free();
  626. } // TTestApplication::MakeSaveDialog 
  627.  
  628. //----------------------------------------------------------------------------------------
  629. // TTestApplication::MakeModalBeepDialog: 
  630. //----------------------------------------------------------------------------------------
  631. void TTestApplication::MakeModalBeepDialog(CommandNumber aCommandNumber)
  632.  
  633. {
  634.     TWindow *    aWindow;
  635.     IDType        dismisser;
  636.     long        n;
  637.  
  638.     FailNIL(aWindow = gViewServer->NewTemplateWindow((short)aCommandNumber, NULL));
  639.     dismisser = aWindow->PoseModally();
  640.     if (dismisser == 'ok  ')
  641.         n = ((TNumberText *)(aWindow->FindSubView('numb')))->GetValue();
  642.     else
  643.         n = 0;
  644.     aWindow->CloseAndFree();
  645.     for (long i = 1; i <= n; i++)
  646.         gApplication->Beep(2);
  647. } // TTestApplication::MakeModalBeepDialog 
  648.  
  649. //----------------------------------------------------------------------------------------
  650. // TTestApplication::MakeDialog: 
  651. //----------------------------------------------------------------------------------------
  652. void TTestApplication::MakeDialog(CommandNumber aCommandNumber)
  653.  
  654. {
  655.     TWindow *    aWindow;
  656.  
  657.  
  658.     FailNIL(aWindow = gViewServer->NewTemplateWindow((short)aCommandNumber, NULL));
  659.     aWindow->Open();
  660. } // TTestApplication::MakeDialog 
  661.  
  662. //----------------------------------------------------------------------------------------
  663. // TTestApplication::MakeBalloonWindow: 
  664. //----------------------------------------------------------------------------------------
  665. void TTestApplication::MakeBalloonWindow(CommandNumber aCommandNumber)
  666. {
  667.     TWindow *    aWindow;
  668.     TView *        aSubView;
  669.  
  670.  
  671.     FailNIL(aWindow = gViewServer->NewTemplateWindow((short)aCommandNumber, NULL));
  672.     aSubView = aWindow->FindSubView('ADN1');
  673.     aSubView->fHelpID = 128;
  674.     aSubView->fHelpIndex = 1;
  675.     aSubView->fCursorID = plusCursor;
  676.  
  677.     aSubView = aWindow->FindSubView('ADN2');
  678.     aSubView->fHelpID = 128;
  679.     aSubView->fHelpIndex = 2;
  680.     aSubView->fHandlesCursor = FALSE;
  681.  
  682.     aSubView = aWindow->FindSubView('ADN3');
  683.     aSubView->fHelpID = 128;
  684.     aSubView->fHelpIndex = 3;
  685.  
  686.     aWindow->Open();
  687. } // TTestApplication::MakeBalloonWindow 
  688.  
  689. //----------------------------------------------------------------------------------------
  690. // TTestApplication::MakeFormatDialog: 
  691. //----------------------------------------------------------------------------------------
  692. void TTestApplication::MakeFormatDialog(CommandNumber aCommandNumber)
  693.  
  694. {
  695.     TWindow *        aWindow;
  696.     TDialogView *    theDialog;
  697.     IDType            dismisser;
  698.  
  699.     FailNIL(aWindow = gViewServer->NewTemplateWindow((short)aCommandNumber, NULL));
  700.     theDialog = (TDialogView *)(aWindow->FindSubView('DLOG'));
  701.     SetupTheFontView(theDialog);
  702.  
  703.     dismisser = aWindow->PoseModally();
  704. #if qDebug
  705.     if (dismisser != 'ok  ')
  706.         fprintf(stderr, "The dialog was cancelled.\n");
  707. #endif
  708.  
  709.     aWindow->CloseAndFree();
  710. } // TTestApplication::MakeFormatDialog 
  711.  
  712. //----------------------------------------------------------------------------------------
  713. // TTestApplication::SetupTheFontView: 
  714. //----------------------------------------------------------------------------------------
  715. void TTestApplication::SetupTheFontView(TDialogView* theDialog)
  716.  
  717. {
  718.     TFontListView * theFontListView;
  719.     TSizeListView * theSizeListView;
  720.  
  721.  
  722.     theSizeListView = (TSizeListView *)(theDialog->FindSubView('slst'));
  723.     theSizeListView->fSelection = 0;
  724.     theSizeListView->fSelectedSize = 9;
  725.     theFontListView = (TFontListView *)(theDialog->FindSubView('flst'));
  726.     theFontListView->InitFontList();
  727.     theFontListView->SelectItem(1, kDontExtend, kHighlight, kSelect);
  728. } // TTestApplication::SetupTheFontView 
  729.  
  730. //----------------------------------------------------------------------------------------
  731. // TTestApplication::MakePageSetupDialog: 
  732. //----------------------------------------------------------------------------------------
  733. void TTestApplication::MakePageSetupDialog(CommandNumber aCommandNumber)
  734.  
  735. {
  736.     TWindow *            aWindow;
  737.     TPageSetupDialog *    theDialog;
  738.     IDType                dismisser;
  739.  
  740.  
  741.     FailNIL(aWindow = gViewServer->NewTemplateWindow((short)aCommandNumber, NULL));
  742.     theDialog = (TPageSetupDialog *)(aWindow->FindSubView('DLOG'));
  743.  
  744.     dismisser = aWindow->PoseModally();
  745. #if qDebug
  746.     if (dismisser == 'ok  ')
  747.     {
  748.     }
  749.     else
  750.         fprintf(stderr, "The dialog was cancelled.\n");
  751. #endif
  752.  
  753.     aWindow->CloseAndFree();
  754. } // TTestApplication::MakePageSetupDialog 
  755.  
  756. //----------------------------------------------------------------------------------------
  757. // TTestApplication::MakeCalculator: 
  758. //----------------------------------------------------------------------------------------
  759. void TTestApplication::MakeCalculator(CommandNumber aCommandNumber)
  760.  
  761. {
  762.     TWindow *        aWindow;
  763.     TCalcDialog *    aCalcDialog;
  764.  
  765.  
  766.     FailNIL(aWindow = gViewServer->NewTemplateWindow((short)aCommandNumber, NULL));
  767.     aCalcDialog = (TCalcDialog *)(aWindow->FindSubView('DLOG'));
  768.     aCalcDialog->ClearSum();
  769.     aWindow->Open();
  770. } // TTestApplication::MakeCalculator 
  771.  
  772. //----------------------------------------------------------------------------------------
  773. // TTestApplication::MakeHomeBrewDialog: 
  774. //----------------------------------------------------------------------------------------
  775. void TTestApplication::MakeHomeBrewDialog(CommandNumber aCommandNumber)
  776. {
  777.     TWindow *            aWindow;
  778.     TScrollBar *        firstScrollBar;
  779.     TScrollBar *        secondScrollBar;
  780.     TChangeBehavior *    aChangeBehavior;
  781.     TUpdateBehavior *    anUpdateBehavior;
  782.  
  783.  
  784.     FailNIL(aWindow = gViewServer->NewTemplateWindow((short)aCommandNumber, NULL));
  785.     firstScrollBar = (TScrollBar *)(aWindow->FindSubView('Scr1'));
  786.     secondScrollBar = (TScrollBar *)(aWindow->FindSubView('Scr2'));
  787.     firstScrollBar->AddDependent(secondScrollBar);
  788.     secondScrollBar->AddDependent(firstScrollBar);
  789.  
  790.     aChangeBehavior = new TChangeBehavior;
  791.     aChangeBehavior->IBehavior(kNoIdentifier);
  792.     firstScrollBar->AddBehavior(aChangeBehavior);
  793.  
  794.     aChangeBehavior = new TChangeBehavior;
  795.     aChangeBehavior->IBehavior(kNoIdentifier);
  796.     secondScrollBar->AddBehavior(aChangeBehavior);
  797.  
  798.     anUpdateBehavior = new TUpdateBehavior;
  799.     anUpdateBehavior->IBehavior(kNoIdentifier);
  800.     firstScrollBar->AddBehavior(anUpdateBehavior);
  801.  
  802.     anUpdateBehavior = new TUpdateBehavior;
  803.     anUpdateBehavior->IBehavior(kNoIdentifier);
  804.     secondScrollBar->AddBehavior(anUpdateBehavior);
  805.  
  806.     aWindow->Open();
  807. } // TTestApplication::MakeHomeBrewDialog 
  808.  
  809.  
  810. //========================================================================================
  811. // CLASS TNumbersView
  812. //========================================================================================
  813. #undef Inherited
  814. #define Inherited TView
  815.  
  816. #pragma segment ARes
  817. MA_DEFINE_CLASS_M1(TNumbersView, Inherited);
  818.  
  819. //----------------------------------------------------------------------------------------
  820. // TNumbersView destructor
  821. //----------------------------------------------------------------------------------------
  822. #pragma segment MADestructorRes
  823.  
  824. TNumbersView::~TNumbersView()
  825. {
  826. }
  827.  
  828. //----------------------------------------------------------------------------------------
  829. // TNumbersView::ReadFields: 
  830. //----------------------------------------------------------------------------------------
  831. #pragma segment ARes
  832. void TNumbersView::ReadFields(TStream* aStream)// override 
  833. {
  834.     Inherited::ReadFields(aStream);
  835.     fWantsToBeTarget = TRUE;
  836. } // TNumbersView::ReadFields 
  837.  
  838. //----------------------------------------------------------------------------------------
  839. // TNumbersView::Draw: 
  840. //----------------------------------------------------------------------------------------
  841. #pragma segment ARes
  842.  
  843. void TNumbersView::Draw(const VRect& area)
  844. {
  845.     VRect viewRect(area);
  846.     viewRect[botRight] -= VPoint(1, 1);
  847.  
  848.     long firstLine = (viewRect.top / 16) + 1;
  849.     long lastLine = (viewRect.bottom / 16) + 1;
  850.  
  851.     SetPortTextStyle(gSystemStyle);
  852.     for (long i = firstLine; i <= lastLine; i++)
  853.     {
  854.         MoveToPt(ViewToQDPt(VPoint(0, i * 16)));
  855.  
  856.         CStr255 s;
  857.         NumToString(i, s);
  858.         DrawString(s);
  859.     }
  860.     Inherited::Draw(area);
  861. } // TNumbersView::Draw 
  862.  
  863. //========================================================================================
  864. // CLASS TNumberListView
  865. //========================================================================================
  866. #undef Inherited
  867. #define Inherited TTextListView
  868.  
  869. #pragma segment ARes
  870. MA_DEFINE_CLASS_M1(TNumberListView, Inherited);
  871.  
  872. //----------------------------------------------------------------------------------------
  873. // TNumberListView constructor
  874. //----------------------------------------------------------------------------------------
  875. #pragma segment ARes
  876.  
  877. TNumberListView::TNumberListView()
  878. {
  879. }
  880.  
  881. //----------------------------------------------------------------------------------------
  882. // TNumberListView destructor
  883. //----------------------------------------------------------------------------------------
  884. #pragma segment MADestructorRes
  885.  
  886. TNumberListView::~TNumberListView()
  887. {
  888. }
  889.  
  890. //----------------------------------------------------------------------------------------
  891. // TNumberListView::DoPostCreate: 
  892. //----------------------------------------------------------------------------------------
  893. #pragma segment ARes
  894. void TNumberListView::DoPostCreate(TDocument* itsDocument)// override 
  895. {
  896.     Inherited::DoPostCreate(itsDocument);
  897.     fWantsToBeTarget = TRUE;                    // !!! should be set in 3.0 'View' resource
  898. } // TNumberListView::DoPostCreate 
  899.  
  900. //----------------------------------------------------------------------------------------
  901. // TNumberListView::BecameWindowTarget: 
  902. //----------------------------------------------------------------------------------------
  903. #pragma segment ARes
  904. void TNumberListView::BecameWindowTarget()// override 
  905. {
  906.     this->DoHighlightSelection(fActiveHL, hlOn);
  907.     fActiveHL = hlOn;
  908.     Inherited::BecameWindowTarget();
  909. } // TNumberListView::BecameWindowTarget 
  910.  
  911. //----------------------------------------------------------------------------------------
  912. // TNumberListView::ResignedWindowTarget: 
  913. //----------------------------------------------------------------------------------------
  914. void TNumberListView::ResignedWindowTarget()// override 
  915. {
  916.     this->DoHighlightSelection(fActiveHL, hlDim);
  917.     fActiveHL = hlDim;
  918.     Inherited::ResignedWindowTarget();
  919. } // TNumberListView::ResignedWindowTarget 
  920.  
  921. //----------------------------------------------------------------------------------------
  922. // TNumberListView::GetItemText: 
  923. //----------------------------------------------------------------------------------------
  924. #pragma segment ARes
  925.  
  926. void TNumberListView::GetItemText(short        anItem,
  927.                                          CStr255&    aString)// override 
  928. {
  929.     NumToString(anItem, aString);
  930. } // TNumberListView::GetItemText 
  931.  
  932.  
  933.  
  934. //========================================================================================
  935. // CLASS TModelessBeepDialog
  936. //========================================================================================
  937. #undef Inherited
  938. #define Inherited TDialogView
  939.  
  940. #pragma segment ARes
  941. MA_DEFINE_CLASS_M1(TModelessBeepDialog, Inherited);
  942.  
  943. //----------------------------------------------------------------------------------------
  944. // TModelessBeepDialog destructor
  945. //----------------------------------------------------------------------------------------
  946. #pragma segment MADestructorRes
  947.  
  948. TModelessBeepDialog::~TModelessBeepDialog()
  949. {
  950. }
  951.  
  952. //----------------------------------------------------------------------------------------
  953. // TModelessBeepDialog::DoEvent: 
  954. //----------------------------------------------------------------------------------------
  955. #pragma segment ARes
  956.  
  957. void TModelessBeepDialog::DoEvent(EventNumber    eventNumber,
  958.                                          TEventHandler*    source,
  959.                                          TEvent*        event)// override 
  960. {
  961.     long i;
  962.     long maxi;
  963.  
  964.     switch (eventNumber)
  965.     {
  966.         case mButtonHit:                        // Default button and Enter or Return key
  967.             {
  968.                 maxi = ((TNumberText *)(FindSubView('numb')))->GetValue();
  969.                 if (this->IsHierarchyValid())
  970.                     for (i = 1; i <= maxi; i++)
  971.                         gApplication->Beep(2);
  972.                 break;
  973.             }
  974.         default:
  975.             Inherited::DoEvent(eventNumber, source, event);
  976.     }
  977. } // TModelessBeepDialog::DoEvent 
  978.  
  979.  
  980. //========================================================================================
  981. // CLASS TMonthlyDialog
  982. //========================================================================================
  983. #undef Inherited
  984. #define Inherited TDialogView
  985.  
  986. #pragma segment ARes
  987. MA_DEFINE_CLASS_M1(TMonthlyDialog, Inherited);
  988.  
  989. //----------------------------------------------------------------------------------------
  990. // TMonthlyDialog destructor
  991. //----------------------------------------------------------------------------------------
  992. #pragma segment MADestructorRes
  993.  
  994. TMonthlyDialog::~TMonthlyDialog()
  995. {
  996. }
  997.  
  998. //----------------------------------------------------------------------------------------
  999. // TMonthlyDialog::Close: 
  1000. //----------------------------------------------------------------------------------------
  1001. #pragma segment AClose
  1002.  
  1003. void TMonthlyDialog::Close()            // override 
  1004.  
  1005. {
  1006.  
  1007.     if (this->IsHierarchyValid())
  1008.     {
  1009.         for (short i = 0; i < 12; i++)
  1010.         {
  1011.             gMonthlyValues[i] = ((TNumberText *)FindSubView(gMonthIDs[i]))->GetValue();
  1012.             Inherited::Close();
  1013.         }
  1014.  
  1015.     }
  1016.     else
  1017.         Failure(noErr, 0);                        // Silent Failure 
  1018.  
  1019. } // TMonthlyDialog::Close 
  1020.  
  1021. //----------------------------------------------------------------------------------------
  1022. // TMonthlyDialog::DoKeyEvent: 
  1023. //----------------------------------------------------------------------------------------
  1024. #pragma segment ARes
  1025.  
  1026. void TMonthlyDialog::DoKeyEvent(TToolboxEvent* event)// override 
  1027. {
  1028.     // If option-tab is pressed, deselect the current edit text and leave nothing
  1029.     // selected. This is for test purposes only. It is not part of the Macintosh user
  1030.     // interface.
  1031.     if ((event->fText == chTab) && (event->IsOptionKeyPressed()))
  1032.         GetWindow()->BecomeTarget();    // Formerly: DoSelectEditText(NULL, FALSE); 
  1033.     else
  1034.         Inherited::DoKeyEvent(event);
  1035. } // TMonthlyDialog::DoKeyEvent 
  1036.  
  1037. //----------------------------------------------------------------------------------------
  1038. // TMonthlyDialog::StuffValues: 
  1039. //----------------------------------------------------------------------------------------
  1040. #pragma segment ARes
  1041.  
  1042. void TMonthlyDialog::StuffValues()
  1043. {
  1044.     for (short i = 0; i < 12; i++)
  1045.         ((TNumberText *)FindSubView(gMonthIDs[i]))->SetValue(gMonthlyValues[i], kDontRedraw);
  1046. } // TMonthlyDialog::StuffValues 
  1047.  
  1048.  
  1049. //========================================================================================
  1050. // GLOBAL Procedures
  1051. //========================================================================================
  1052. #undef Inherited
  1053.  
  1054. //----------------------------------------------------------------------------------------
  1055. // GetFontNumber: 
  1056. //----------------------------------------------------------------------------------------
  1057. #pragma segment ARes
  1058.  
  1059. // From IM-VI p. 12-16:
  1060.  
  1061. Boolean GetFontNumber( CStr255& fontName, short& fontNumber )
  1062. {    
  1063.     GetFNum( fontName, &fontNumber );
  1064.     if( fontNumber == 0 )
  1065.     {
  1066.         CStr255        systemFontName;
  1067.         
  1068.         // Either the font was not found, or it is the system font
  1069.         
  1070.         GetFontName( 0, systemFontName );
  1071.         return systemFontName == fontName;
  1072.     }
  1073.     
  1074.     return TRUE;
  1075. } // GetFontNumber 
  1076.  
  1077.  
  1078. //========================================================================================
  1079. // CLASS TFontListView
  1080. //========================================================================================
  1081. #undef Inherited
  1082. #define Inherited TTextListView
  1083.  
  1084. #pragma segment AOpen
  1085. MA_DEFINE_CLASS_M1(TFontListView, Inherited);
  1086.  
  1087. //----------------------------------------------------------------------------------------
  1088. // TFontListView::DoPostCreate: 
  1089. //----------------------------------------------------------------------------------------
  1090. #pragma segment AOpen
  1091.  
  1092. void TFontListView::DoPostCreate(TDocument* itsDocument)// override 
  1093.  
  1094. {
  1095.     Inherited::DoPostCreate(itsDocument);
  1096.     fWantsToBeTarget = TRUE;
  1097. } // TFontListView::DoPostCreate 
  1098.  
  1099. //----------------------------------------------------------------------------------------
  1100. // TFontListView::InitFontList: 
  1101. //----------------------------------------------------------------------------------------
  1102. #pragma segment AOpen
  1103.  
  1104. void TFontListView::InitFontList()
  1105.  
  1106. {
  1107.     TKeySelectionBehavior *    behavior;
  1108.     FontListPtr                pFondIDs;
  1109.     short                    i;
  1110.     short                    noOfFonds;
  1111.     CStr255                    aString;
  1112.  
  1113.     behavior = new TKeySelectionBehavior;
  1114.     behavior->IKeySelectionBehavior('KYSL');
  1115.     AddBehavior(behavior);
  1116.  
  1117.     fFontList = NULL;
  1118.     noOfFonds = CountResources('FOND');
  1119.     if (noOfFonds > kMaxFonds)
  1120.         noOfFonds = kMaxFonds;
  1121.     pFondIDs = FontListPtr(NewPermPtr( (noOfFonds + 1) * 2));    // Our indexing scheme is one-based
  1122.                                                                 // element zero is unused, so we'd better get one more item
  1123.  
  1124.     aString = " ";
  1125.     for (i = 1; i <= noOfFonds; i++)
  1126.     {                                                    // put each FOND's id in the list… 
  1127.         (*pFondIDs)[i] = FondAfter(aString, noOfFonds);    // …in alphabetical order 
  1128.         if (aString.Length() == 0)                        // we finished early 
  1129.         {
  1130.             noOfFonds = i - 1;
  1131.             break;
  1132.         }
  1133.     }
  1134.  
  1135.     fFontList = pFondIDs;
  1136.     InsRowLast(noOfFonds, 16);
  1137. } // TFontListView::InitFontList 
  1138.  
  1139. //----------------------------------------------------------------------------------------
  1140. // TFontListView::FondAfter: 
  1141. //----------------------------------------------------------------------------------------
  1142. #pragma segment AOpen
  1143.  
  1144. short TFontListView::FondAfter(CStr255&    fontName,
  1145.                                       short        noOfFonds)
  1146. // Find the FOND whose name follows fontName alphabetically, and return its id and name 
  1147.  
  1148. {
  1149.     Handle    theFondResource;
  1150.     short    lastID;
  1151.     short    thisResID;
  1152.     short    thisID;
  1153.     ResType    itsType;
  1154.     short    index;
  1155.     Boolean    foundFOND;
  1156.     CStr255    lastName;
  1157.     CStr255    thisName;
  1158.  
  1159.  
  1160.     foundFOND = FALSE;
  1161.     lastName = "~~~~~~~~";
  1162.     lastID = 0;
  1163.     for (index = 1; index <= noOfFonds; index++)
  1164.     {
  1165.         theFondResource = GetIndResource('FOND', index);
  1166.         GetResInfo(theFondResource, &thisResID, &itsType, thisName);
  1167.         if( GetFontNumber( thisName, thisID ) )            // Remember the font number, not its resource ID
  1168.         {
  1169.             if ((thisName > fontName) && (thisName < lastName))
  1170.             {
  1171.                 lastID = thisID;
  1172.                 lastName = thisName;
  1173.                 foundFOND = TRUE;
  1174.             }
  1175.         }
  1176.     }
  1177.     if (foundFOND)
  1178.         fontName = lastName;
  1179.     else                                        // Skip duplicate FOND names 
  1180.         fontName.Empty();
  1181.     return lastID;
  1182. } // TFontListView::FondAfter 
  1183.  
  1184. //----------------------------------------------------------------------------------------
  1185. // TFontListView::Free: 
  1186. //----------------------------------------------------------------------------------------
  1187. #pragma segment AClose
  1188.  
  1189. TFontListView::~TFontListView()            // override 
  1190.  
  1191. {
  1192.     fFontList = (FontListPtr) DisposeIfPtr ((Ptr)fFontList);
  1193. } // TFontListView::Free 
  1194.  
  1195. //----------------------------------------------------------------------------------------
  1196. // TFontListView::GetItemText: 
  1197. //----------------------------------------------------------------------------------------
  1198. #pragma segment ARes
  1199.  
  1200. void TFontListView::GetItemText(short    anItem,
  1201.                                        CStr255&    aString)
  1202. {
  1203.     GetFontName( (*fFontList)[anItem], aString );
  1204. } // TFontListView::GetItemText 
  1205.  
  1206. //----------------------------------------------------------------------------------------
  1207. // TFontListView::SelectItem: 
  1208. //----------------------------------------------------------------------------------------
  1209. #pragma segment ARes
  1210.  
  1211. void TFontListView::SelectItem(short        anItem,
  1212.                                       Boolean    extendSelection,
  1213.                                       Boolean    highlight,
  1214.                                       Boolean    select)
  1215. {
  1216.     TView * aView;
  1217.  
  1218.     Inherited::SelectItem(anItem, extendSelection, highlight, select);
  1219.  
  1220.     if (select)
  1221.     {
  1222.         aView = ((TView *)GetWindow())->FindSubView('slst');
  1223.         FailNILResource((Handle)aView);
  1224.         ((TSizeListView *)aView)->InstallFontFamily((*fFontList)[anItem]);
  1225.     }
  1226. } // TFontListView::SelectItem 
  1227.  
  1228.  
  1229. //========================================================================================
  1230. // CLASS TSizeListView
  1231. //========================================================================================
  1232. #undef Inherited
  1233. #define Inherited TTextListView
  1234.  
  1235. #pragma segment ARes
  1236. MA_DEFINE_CLASS_M1(TSizeListView, Inherited);
  1237.  
  1238. //----------------------------------------------------------------------------------------
  1239. // TSizeListView destructor
  1240. //----------------------------------------------------------------------------------------
  1241. #pragma segment MADestructorRes
  1242.  
  1243. TSizeListView::~TSizeListView()
  1244. {
  1245. }
  1246.  
  1247. //----------------------------------------------------------------------------------------
  1248. // TSizeListView::GetItemText: 
  1249. //----------------------------------------------------------------------------------------
  1250. #pragma segment ARes
  1251.  
  1252. void TSizeListView::GetItemText(short    anItem,
  1253.                                        CStr255&    aString)            // override 
  1254. {
  1255.     NumToString( fFontSizeList[anItem - 1], aString);
  1256. } // TSizeListView::GetItemText 
  1257.  
  1258. //----------------------------------------------------------------------------------------
  1259. // TSizeListView::InstallFontFamily: 
  1260. //----------------------------------------------------------------------------------------
  1261. #pragma segment AOpen
  1262.  
  1263. void TSizeListView::InstallFontFamily(short theFontNumber)
  1264. {    
  1265.     short        noOfSizes;
  1266.     short        sizeToSelect;
  1267.     
  1268.     noOfSizes = 0;
  1269.     sizeToSelect = 0;
  1270.  
  1271.     // We only check a specific set of Font sizes, as recommended in IM VI p. 12-15    
  1272.     for( short fontSize = 9; fontSize <= 96; ++fontSize )
  1273.     {
  1274.         // Check the same set of font sizes that MPW does: every point size from 9 to 24,
  1275.         // then every 6th point size up to size 96.
  1276.         if( (fontSize <= 24) || (fontSize % 6 == 0) )
  1277.         {
  1278.             // If this font size is available & there is room in the table…
  1279.             if( RealFont( theFontNumber, fontSize ) && (noOfSizes < kMaxSizes) )
  1280.             {
  1281.                 // …then remember this value
  1282.                 fFontSizeList[noOfSizes] = fontSize;
  1283.                 
  1284.                 noOfSizes = noOfSizes + 1;
  1285.                 if( fontSize == fSelectedSize )
  1286.                     sizeToSelect = noOfSizes;
  1287.             }
  1288.         }
  1289.     }
  1290.     
  1291.     SetNumberOfItems(noOfSizes);
  1292.     SelectItem(sizeToSelect, kDontExtend, kDontHighlight, kSelect);
  1293.     ForceRedraw();
  1294. } // TSizeListView::InstallFontFamily 
  1295.  
  1296. //----------------------------------------------------------------------------------------
  1297. // TSizeListView::SelectItem: 
  1298. //----------------------------------------------------------------------------------------
  1299. #pragma segment ARes
  1300.  
  1301. void TSizeListView::SelectItem(short        anItem,
  1302.                                       Boolean    extendSelection,
  1303.                                       Boolean    highlight,
  1304.                                       Boolean    select)// override 
  1305. {
  1306.     CStr255            aString;
  1307.     TNumberText *    theSizeView;
  1308.     long            fontSize;
  1309.  
  1310.  
  1311.     Inherited::SelectItem(anItem, extendSelection, highlight, select);
  1312.  
  1313.     if (select && (anItem != 0))
  1314.     {
  1315.         GetItemText(anItem, aString);
  1316.         theSizeView = (TNumberText *)(GetWindow()->FindSubView('size'));
  1317.         theSizeView->SetText(aString, kRedraw);
  1318.         theSizeView->SetSelection(0, SHRT_MAX, kRedraw);
  1319.         StringToNum(aString, &fontSize);
  1320.         fSelectedSize = (short)fontSize;
  1321.     }
  1322. } // TSizeListView::SelectItem 
  1323.  
  1324. //----------------------------------------------------------------------------------------
  1325. // TSizeListView::SetNumberOfItems: 
  1326. //----------------------------------------------------------------------------------------
  1327. #pragma segment ARes
  1328.  
  1329. void TSizeListView::SetNumberOfItems(short aNumber)
  1330. {
  1331.     SelectItem(0, kDontExtend, kHighlight, kSelect);
  1332.  
  1333.     if (fNumOfRows > aNumber)
  1334.     {
  1335.         DelItemFirst(fNumOfRows - aNumber);
  1336.     }
  1337.     else if (fNumOfRows < aNumber)
  1338.     {
  1339.         InsItemFirst(aNumber - fNumOfRows);
  1340.     }
  1341. } // TSizeListView::SetNumberOfItems 
  1342.  
  1343.  
  1344. //========================================================================================
  1345. // CLASS TPageSetupDialog
  1346. //========================================================================================
  1347. #undef Inherited
  1348. #define Inherited TDialogView
  1349.  
  1350. #pragma segment ARes
  1351. MA_DEFINE_CLASS_M1(TPageSetupDialog, Inherited);
  1352.  
  1353. //----------------------------------------------------------------------------------------
  1354. // TPageSetupDialog constructor 
  1355. //----------------------------------------------------------------------------------------
  1356. #pragma segment ARes
  1357.  
  1358. TPageSetupDialog::TPageSetupDialog()     
  1359. {
  1360.     fOrientation = vSel;
  1361.     fTallAdjusted = NULL;
  1362.     fVerticalOrientation = NULL;
  1363.     fHorizontalOrientation = NULL;
  1364. } // TPageSetupDialog::TPageSetupDialog 
  1365.  
  1366. //----------------------------------------------------------------------------------------
  1367. // TPageSetupDialog destructor
  1368. //----------------------------------------------------------------------------------------
  1369. #pragma segment MADestructorRes
  1370.  
  1371. TPageSetupDialog::~TPageSetupDialog()
  1372. {
  1373. }
  1374.  
  1375. //----------------------------------------------------------------------------------------
  1376. // TPageSetupDialog::DoPostCreate: 
  1377. //----------------------------------------------------------------------------------------
  1378. #pragma segment AOpen
  1379.  
  1380. void TPageSetupDialog::DoPostCreate(TDocument* itsDocument)
  1381. {
  1382.     Inherited::DoPostCreate(itsDocument);
  1383.  
  1384.     fTallAdjusted = (TCheckBox *)(this->FindSubView('tall'));
  1385.     fVerticalOrientation = (TRadioIcon *)(this->FindSubView('vert'));
  1386.     fHorizontalOrientation = (TRadioIcon *)(this->FindSubView('horz'));
  1387.  
  1388.     fVerticalOrientation->HiliteState(fOrientation == vSel, kDontRedraw);
  1389.     fHorizontalOrientation->HiliteState(fOrientation == hSel, kDontRedraw);
  1390. } // TPageSetupDialog::DoPostCreate 
  1391.  
  1392. //----------------------------------------------------------------------------------------
  1393. // TPageSetupDialog::DoEvent: 
  1394. //----------------------------------------------------------------------------------------
  1395. #pragma segment ARes
  1396.  
  1397. void TPageSetupDialog::DoEvent(EventNumber        eventNumber,
  1398.                                       TEventHandler*    source,
  1399.                                       TEvent*            event)// override 
  1400. {
  1401.     VHSelect newOrientation;
  1402.  
  1403.     switch (eventNumber)
  1404.     {
  1405.         case mIconHit:
  1406.             {
  1407.                 if (source == fVerticalOrientation)
  1408.                     newOrientation = vSel;
  1409.                 else
  1410.                     newOrientation = hSel;
  1411.                 if (newOrientation != fOrientation)
  1412.                 {
  1413.                     fVerticalOrientation->HiliteState(newOrientation == vSel, kRedraw);
  1414.                     fHorizontalOrientation->HiliteState(newOrientation == hSel, kRedraw);
  1415.                     fTallAdjusted->DimState(newOrientation == hSel, kRedraw);
  1416.                     fTallAdjusted->SetState(FALSE, kRedraw);
  1417.                     fOrientation = newOrientation;
  1418.                 }
  1419.                 break;
  1420.             }
  1421.         default:
  1422.             Inherited::DoEvent(eventNumber, source, event);
  1423.     } // switch
  1424. } // TPageSetupDialog::DoEvent 
  1425.  
  1426.  
  1427.  
  1428. //========================================================================================
  1429. // CLASS TRadioIcon
  1430. //========================================================================================
  1431. #undef Inherited
  1432. #define Inherited TIcon
  1433.  
  1434. #pragma segment ARes
  1435. MA_DEFINE_CLASS_M1(TRadioIcon, Inherited);
  1436.  
  1437. //----------------------------------------------------------------------------------------
  1438. // TRadioIcon destructor
  1439. //----------------------------------------------------------------------------------------
  1440. #pragma segment MADestructorRes
  1441.  
  1442. TRadioIcon::~TRadioIcon()
  1443. {
  1444. }
  1445.  
  1446. //----------------------------------------------------------------------------------------
  1447. // TRadioIcon::TrackMouse: 
  1448. //----------------------------------------------------------------------------------------
  1449. #pragma segment ADoCommand
  1450.  
  1451. void TRadioIcon::TrackMouse(TrackPhase    aTrackPhase,
  1452.                                    VPoint&        /*anchorPoint*/,
  1453.                                    VPoint&        /*previousPoint*/,
  1454.                                    VPoint&        /*nextPoint*/,
  1455.                                    Boolean        /*mouseDidMove*/)// override 
  1456. {
  1457.     if (aTrackPhase == trackBegin)
  1458.         this->HandleEvent(mIconHit, this, NULL);
  1459.  
  1460. } // TRadioIcon::TrackMouse 
  1461.  
  1462.  
  1463. //========================================================================================
  1464. // CLASS TRoundView
  1465. //========================================================================================
  1466. #undef Inherited
  1467. #define Inherited TControl
  1468.  
  1469. #pragma segment ARes
  1470. MA_DEFINE_CLASS_M1(TRoundView, Inherited);
  1471.  
  1472. //----------------------------------------------------------------------------------------
  1473. // TRoundView constructor
  1474. //----------------------------------------------------------------------------------------
  1475. #pragma segment AOpen
  1476.  
  1477. TRoundView::TRoundView()
  1478. {
  1479. }
  1480.  
  1481. //----------------------------------------------------------------------------------------
  1482. // TRoundView destructor
  1483. //----------------------------------------------------------------------------------------
  1484. #pragma segment MADestructorRes
  1485.  
  1486. TRoundView::~TRoundView()
  1487. {
  1488. }
  1489.  
  1490. //----------------------------------------------------------------------------------------
  1491. // TRoundView::Draw
  1492. //----------------------------------------------------------------------------------------
  1493. #pragma segment ARes
  1494.  
  1495. void TRoundView::Draw(const VRect& area)
  1496. {
  1497.     EraseRect(&ViewToQDRect(area));
  1498. }
  1499.  
  1500. //----------------------------------------------------------------------------------------
  1501. // TRoundView::GetExtentRegion: 
  1502. //----------------------------------------------------------------------------------------
  1503. #pragma segment ARes
  1504.  
  1505. void TRoundView::GetExtentRegion(RgnHandle itsExtentRgn)// override 
  1506. {
  1507.     //
  1508.     // This is a simple example of a view that has a non-rectangular region.
  1509.     // For simplicity we are actually constructing the region in this method.
  1510.     // If we wanted, we could construct the region some other time (ReadFrom/DoPostCreate/etc.)
  1511.     // and store it. Then we would simply copy the region in this method.
  1512.     //
  1513.  
  1514.     OpenRgn();
  1515.     FrameOval(&GetQDExtent());
  1516.     CloseRgn(itsExtentRgn);
  1517. } // TRoundView::GetExtentRegion 
  1518.  
  1519. //----------------------------------------------------------------------------------------
  1520. // End of UDemoDialogs.cp
  1521.  
  1522. #pragma segment Inline
  1523.